#include <iostream>
#include <stdio.h>
#include <assert.h>

using namespace std;

//c语言标准输入输出
class date 
{
    friend ostream& operator<<(ostream& _cout, const date& d);
public:
    date(int year = 2022, int month = 10, int day = 6)
        :_year(year)
         ,_month(month)
         ,_day(day)
    {}

private:
    int _year;
    int _month;
    int _day;
};

ostream& operator<<(ostream& _cout, const date& d)
{
    std::cout << "year = " << d._year 
        << ",month = "<< d._month 
        << ",day = " << d._day; 
    return _cout;
}

//int main()
//{
//    int i = 1;
//    double d = 2.2;
//    date d1;
//
//    //scanf/printf的缺点是只能支持内置类型
//    //对于自定义类型,如果是私有对象,那么里面的对象不能够访问
//    //cin/cout的真正优势是,自己重载以后,可以使用自定义类型对象
//    printf("i = %d,d = %lf\n", i, d);
//    cout << "i = " << i << ", " << "d = " << d  << endl << d1 << endl; 
//    return 0;
//}

//c语言文件的输入输出

struct server_info
{
    char _ip[32];
    int _port;

    date _d;
};

int main()
{
    //FILE* fp1 = fopen("./myfile.txt", "wb+");
    //assert(fp1);

    ////文本形式格式化的向文件里面写入东西
    //int i = 10;
    //char str[100];
    //fprintf(fp1, "i = %d, test\n", i);

    ////让文件指针的位置回到文件的起始位置
    //rewind(fp1);

    ////文本形式格式化的从文件里面读取东西
    //while(fscanf(fp1, "%s", str) != EOF)
    //{
    //    cout << str;
    //}
    //cout << endl;
    
    //FILE* fp1 = fopen("./myfile.txt", "wb+");
    //assert(fp1);
    ////二进制写入,文件中会有乱码
    ////如果是字符,那么不会出错,如果是int,double等,就会乱码
    //server_info info = {"127.0.0.1", 80};
    //fwrite(&info, sizeof(info), 1, fp1);
    //fclose(fp1);

    ////二进制的读取
    //fp1 = fopen("./myfile.txt", "r+");
    //assert(fp1);
    //server_info read;
    //fread(&read, sizeof(info), 1, fp1);
    //fclose(fp1);
    //cout << read._ip  << " " << read._port << endl << read._d << endl; 
    return 0;
}
